import logging
from redis import StrictRedis


class Config(object):
    """工程信息配置"""
    SECRET_KEY = "nEinUKDJ0sMFp3uYY/vSMCBb2l33dxatk9QnHKqR4PvfE1AQXjNvGKw6EmEg9fnI"

    """项目的配置"""
    DEBUG = True

    # redis配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = "6379"
    # falsk_session的配置信息
    SESSION_TYPE = "redis"  # 指定session保存到redis 效率高
    SESSION_USE_SIGNER = True  # 开启session签名,让cookie中的session_id被加密处理
    # 指定Session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    # 设置需要过期
    SESSION_PERMANENT = False
    PERMANENT_SESSION_LIFETIME = 86400 # session的有效时间

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 在请求结束时候，如果指定该配置为True，那么SQLAlchemy会自动执行 db.session.commit()
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # 设置日志等级
    LOG_LEVEL=logging.DEBUG


class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True

class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = True
    LOG_LEVEL = logging.WARNING

class TestingConfig(Config):
    """单元测试环境下的配置"""
    DEBUG = True
    TESTING= True

config = {
    "development" :DevelopmentConfig,
    "production":ProductionConfig,
    "testing":TestingConfig
}
